package com.hq.door.dto;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Set;

import com.hq.door.pojo.TOutRequest;
import com.hq.door.pojo.TParent;
import com.hq.door.pojo.TStudent;
import com.hq.door.util.ExcelUtil;

/**
 * 前台数据	审批记录
 * 作者：袁健宝
 * 日期：2017年1月11日 上午11:26:42
 */
public class ParentApplyFront {
	
	//
	private Date startDate;
	private Date endDate;
	private Integer pageNo;
	private Integer pageSize;
	private String type;	//查询类型
	//家长表
	private String mobile;		//家长手机号，唯一索引
	//学生表
	private String stuName;		//学生姓名
	//外出申请表
	private String majorName;	//专业名称
	private String className;	//班级名称
	private String reasonReq;	//请假原因
	private String spStatus;	//审批状态
	private String startTime;	//外出开始时间
	private String endTime;		//外出结束时间
	
	public ParentApplyFront(){}
	public ParentApplyFront(Date startDate,Date endDate,String type, String mobile, String stuName,String majorName,
			String className, String reasonReq, String spStatus,String startTime, String endTime) {
		this.startDate = startDate;
		this.endDate = endDate;
		this.type = type;
		this.mobile = mobile;
		this.stuName = stuName;
		this.majorName = majorName;
		this.className = className;
		this.reasonReq = reasonReq;
		this.spStatus = spStatus;
		this.startTime = startTime;
		this.endTime = endTime;
	}

	@Override
	public String toString() {
		return "ParentInfoFront [startDate="+startDate+",endDate=" + endDate+",type=" + type + ", mobile=" + mobile + ", stuName="
				+ stuName + ", majorName=" + majorName + ", className=" + className
				+ ", reasonReq=" + reasonReq + ", spStatus=" + spStatus
				+ ", startTime=" + startTime + ", endTime=" + endTime + "]";
	}

	public Date getStartDate() {
		return startDate;
	}
	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}
	public Date getEndDate() {
		return endDate;
	}
	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}
	public Integer getPageNo() {
		return pageNo;
	}

	public void setPageNo(Integer pageNo) {
		this.pageNo = pageNo;
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}
	
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getMobile() {
		return mobile;
	}
	
	public void setMobile(String mobile) {
		this.mobile = mobile;
	}
	
	public String getStuName() {
		return stuName;
	}

	public void setStuName(String stuName) {
		this.stuName = stuName;
	}

	public String getMajorName() {
		return majorName;
	}

	public void setMajorName(String majorName) {
		this.majorName = majorName;
	}

	public String getClassName() {
		return className;
	}

	public void setClassName(String className) {
		this.className = className;
	}

	public String getReasonReq() {
		return reasonReq;
	}

	public void setReasonReq(String reasonReq) {
		this.reasonReq = reasonReq;
	}

	public String getSpStatus() {
		return spStatus;
	}

	public void setSpStatus(String spStatus) {
		this.spStatus = spStatus;
	}

	public String getStartTime() {
		return startTime;
	}

	public void setStartTime(String startTime) {
		this.startTime = startTime;
	}

	public String getEndTime() {
		return endTime;
	}

	public void setEndTime(String endTime) {
		this.endTime = endTime;
	}

	/**
	 * 数据库对象 pojo转换成自定义类
	 * @param parent	
	 * @return
	 */
	public static ParentApplyFront writeApply(TOutRequest toutRequest){
		ParentApplyFront paf = null;
		if(toutRequest!=null){
			paf = new ParentApplyFront();
			paf.setStuName(toStr(toutRequest.getTStudent().getName()));	//学生姓名
			paf.setMajorName(toStr(toutRequest.getTStudent().getTClass().getTMajor().getName()));//专业名称
			paf.setClassName(toStr(toutRequest.getTStudent().getTClass().getName()));	//班级名称
			paf.setReasonReq(toStr(toutRequest.getRequestReason()));			//请假原因
			paf.setSpStatus(sp2Str(toutRequest.getAuthStatus()+""));	//审批状态
			paf.setStartTime(obj2Date(toutRequest.getStartTime()));		//外出开始时间
			paf.setEndTime(obj2Date(toutRequest.getEndTime()));			//外出结束时间
		}
		return paf;
	}
	
	/**
	 * 查询多条记录 外出申请信息
	 * @param tparents
	 * @return
	 */
	public static List<ParentApplyFront> writeApplies(List<TOutRequest> toutRequests){
		List<ParentApplyFront> pafs = new ArrayList<ParentApplyFront>();
		for (TOutRequest toutRequest : toutRequests) {
			ParentApplyFront paf = writeApply(toutRequest);
			pafs.add(paf);
		}
		return pafs;
	}
	
	/**
	 * Long类型转成日期yyyy-MM-dd HH:mm:ss
	 * @param obj
	 * @return
	 */
	private static String obj2Date(Object obj){
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String result = "";
		if(obj!=null){
			if(obj instanceof Long){
				result = sdf.format(new Date((long)obj));
			}else if(obj instanceof Timestamp){
				result = sdf.format(new Date(((Timestamp)obj).getTime()));
			}
		}
		return result;
	}
	
	
	public static String toStr(Object obj){
		return obj==null||!(obj instanceof String)||"".equals(obj)?"":obj.toString();
	}
	
	/**
	 * 审批状态
	 	0-审批中
        1-审批通过
        2-审批驳回
        3-撤销
	 * @return
	 */
	private static String sp2Str(String obj){
		return obj;
		/*
		String result = "";
		if(obj==null){
			return "";
		}else if("0".equals(obj)){
			result = "审批中";
		}else if("1".equals(obj)){
			result = "审批通过";
		}else if("2".equals(obj)){
			result = "审批驳回";
		}else if("3".equals(obj)){
			result = "撤销";
		}
		return result;*/
	}
}
